package pl.shenlon.poker.game;

import java.util.Observable;

import pl.shenlon.poker.cards.Hand;
import pl.shenlon.poker.game.gametypes.PokerGame;

public abstract class PokerPlayer extends Observable {

	protected int cash;

	protected final Hand hand;

	private int wins, loses, ties;

	public PokerPlayer(int cash) {
		this.cash = cash;
		this.hand = new Hand(2);
	}

	public abstract PlayerAction act(PokerGame game,
			PlayerActionType... allowedActionTypes
			);

	public void addCash(int cash) {
		this.cash += cash;
		setChanged();
		notifyObservers(cash);
	}

	public boolean canBet(int amount) {
		return cash >= amount;
	}

	public void clearScores() {
		wins = 0;
		ties = 0;
		loses = 0;
		setChanged();
		notifyObservers();
	}

	public int getCash() {
		return cash;
	}

	public Hand getHand() {
		return hand;
	}

	public int getLoses() {
		return loses;
	}

	public int getTies() {
		return ties;
	}

	public int getWins() {
		return wins;
	}

	public void setCash(int cash) {
		this.cash = cash;
		setChanged();
		notifyObservers();
	}

	public void setLoses(int loses) {
		this.loses = loses;
		setChanged();
		notifyObservers();
	}

	public void setTies(int ties) {
		this.ties = ties;
		setChanged();
		notifyObservers();
	}

	public void setWins(int wins) {
		this.wins = wins;
		setChanged();
		notifyObservers();
	}

	public int updateLoses(int amount) {
		loses += amount;
		setChanged();
		notifyObservers();
		return loses;
	}

	public int updateTies(int amount) {
		ties += amount;
		setChanged();
		notifyObservers();
		return ties;
	}

	public int updateWins(int amount) {
		wins += amount;
		setChanged();
		notifyObservers();
		return wins;
	}

}